﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using QxFramework.Core;
using UnityEngine.UI;
using System;
using UnityEngine.EventSystems;

public class ObjectBasement : Button
{
    CombineUI root;
    protected override void Awake()
    {
        root = this.transform.parent.parent.GetComponentInParent<CombineUI>();
      /*  if (this.transform.parent.name.StartsWith("base"))
        {
            Debug.Log(ItemField == null);
        }*/
    }

    public override void OnPointerDown(PointerEventData eventData)
    {
        base.OnPointerDown(eventData);
        var tp=this.transform.name;
      //  Debug.Log("!!" + this.GetComponentInParent<ObjectPanel>());
        if (this.GetComponentInParent<ObjectPanel>())
        {
            root.ChangeSelectedObject(this.GetComponentInParent<ObjectPanel>().BenchItemList.Find(x=>x.Item1==this.transform.parent.gameObject));
        }
        else
        {
            root.ChangeSelectedObject(this.GetComponentInParent<BagObjectPanel>().BagItemsList.Find(x => x.Item1 == this.transform.parent.gameObject));

        }
    }
    private void Update()
    {
        if (this.GetComponent<Image>().sprite == null)
        {
            //    this.GetComponent<Image>().sprite = Resources.Load<Sprite>("Texture/UI/Empty");
            this.GetComponent<Image>().color = new Color(1, 1, 1, 0);
        }
        else
        {
            this.GetComponent<Image>().color = Color.white;
        }
    }

}
